<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加设备</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" type="text/css" href="css/main.css" />
  <link rel="stylesheet" type="text/css" href="../mobile/js/layer/css/layui.css" />
  <script src="../mobile/js/jquery-1.9.1.js"></script>
  <script src="../mobile/js/layer/layui.js"></script>
  <script src="./js/common.js"></script>
  <script type="text/javascript">
      //访问是否登录,ajax同步请求
      logins(); 
  </script>
</head>
<body>
<div style="margin: 20px 20px 20px 20px;">
<blockquote class="layui-elem-quote">
   <button class="layui-btn" style="background:#5FB878;" onclick="javascript :history.back(-1);"><i class="layui-icon" style="color: #fff">&#xe65c;</i>返回</button>
   <button class="layui-btn btns"><i class="layui-icon" style="color: #fff">&#xe642;</i>添加设备</button>
</blockquote>
    <div class="x-body layui-anim layui-anim-up">
        <form method="post" class="layui-form">
          <div class="layui-form-item">
              <label for="L_smsform" class="layui-form-label">
                  <span class="x-red">*</span>设备号
              </label>
              <div class="layui-input-block">
                  <textarea placeholder="请输入内容" name="device_sn" class="layui-textarea"  lay-verify="device_sn"
                  autocomplete="off" style="width:90%;height: 300px;" required id="device_sn"></textarea>
              </div>
              <br>
              <div class="layui-form-mid layui-word-aux" style="margin-left:36px;">
                  <span class="x-red">*</span>格式为 : ***,***,***。多个数字的时候，用英文逗号隔开，单个就不用加逗号。
              </div>
          </div>
          <div class="layui-form-item" id="successs" style="display: none;margin-left: 15px;">
              <label for="L_smsform" class="layui-form-label">
                  <span class="x-red">*</span>添加成功设备
              </label>
              <div class="layui-input-block" id="success" style="top: 11px;width: 80%;word-wrap: break-word;word-break:break-all;">
                868658039075911,868658039075913
              </div>
          </div>
          <div class="layui-form-item" id="fails" style="display: none;margin-left: 15px;color: red;">
              <label for="L_smsform" class="layui-form-label" style="color: red;">
                  <span class="x-red">*</span>添加失败设备
              </label>
              <div class="layui-input-block" id="fail" style="top: 11px;width: 80%;word-wrap: break-word;word-break:break-all;color: red;">
                868658039075911,868658039075913
              </div>
          </div>
          <div class="layui-form-item" style="text-align: center;margin-left: -150px;">
             <label for="L_repass" class="layui-form-label">
              </label>
              <button  type="submit" class="layui-btn btns" lay-filter="adddevice" lay-submit="">
                  添加
              </button>
          </div>
      </form>
    </div>
  </div>      
<script>
    layui.use(['form','layer','layedit'], function(){
      var form = layui.form
      ,layer = layui.layer
      ,$ = layui.jquery;
      //自定义验证规则
      form.verify({
        device_sn: [/^(\d{5,25},)*(\d{5,25})+$/, '每组数字，用英文逗号隔开，单个就不用加逗号。']
      });
      //监听提交
      form.on('submit(adddevice)', function(data){
        var urls = url + "/admin/device/adds";

        $.post(urls,data.field,function(msg){
            if(msg.code == 1){
              $("#successs").show();
              $("#fails").show();
              $("#device_sn").val("");
              $("#success").html(msg.successs);
              $("#fail").html(msg.fails);
              layer.alert(msg.infomsg, {icon: 6});
            }else{
              layer.alert(msg.infomsg, {icon: 5}); 
            }
        },'json')
          return false;
      });
    });
</script>
</body>
</html>